﻿using NExt.UI.Browse.Base;
using NExt.Core.Model.Base;
using NExt.UI.Resource.Icon;
using NExt.UI.Base.Js;
using NExt.UI.Base.Right;

namespace NExt.UI.Browse.Data
{
    public class DataBrowsePresenter : BrowsePresenterBase
    {
        public NExt.Toolbar.Button tbbNew;
        public NExt.Toolbar.Button tbbOpen;
        public NExt.Toolbar.Button tbbDelete;
        public IScript rightSetter { get; set; }

        protected IScript onTbbNewInvoked;
        protected IScript onTbbOpenInvoked;
        protected IScript onTbbDeleteInvoked;

        protected readonly static IScript fireNew = new ExternalJs("fireNew");
        protected readonly static IScript fireOpen = new ExternalJs("fireOpen");
        protected readonly static IScript fireDelete = new ExternalJs("fireDelete");

        protected override void FormBuildComponents()
        {
            base.FormBuildComponents();
            this.FormBuildRightSetter();
            tbbNew = new Toolbar.Button();
            tbbOpen = new Toolbar.Button();
            tbbDelete = new Toolbar.Button();
        }

        protected virtual void FormBuildRightSetter()
        {
            rightSetter = new NullRightSetter();
        }

        protected override void FormInitializeEvents()
        {
            base.FormInitializeEvents();
            onTbbNewInvoked = fireNew;
            onTbbOpenInvoked = fireOpen;
            onTbbDeleteInvoked = fireDelete;
        }

        protected override void FormInitializeComponents()
        {
            base.FormInitializeComponents();

            tbbNew.text = "New";
            tbbNew.iconCls = IconCls.New16;
            tbbNew.listeners.click = onTbbNewInvoked;
            toolbar.buttons.Insert(0, tbbNew);

            tbbOpen.text = "Open";
            tbbOpen.iconCls = IconCls.Open16;
            tbbOpen.listeners.click = onTbbOpenInvoked;
            toolbar.buttons.Insert(1, tbbOpen);

            tbbDelete.text = "Delete";
            tbbDelete.iconCls = IconCls.Delete16;
            tbbDelete.listeners.click = onTbbDeleteInvoked;
            toolbar.buttons.Insert(2, tbbDelete);
        }
    }
}
